package com.example.demo;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class cookie {
    @RequestMapping("/abc")
    public String cookietest(HttpServletRequest httpServletRequest){
        Cookie[]cookies=httpServletRequest.getCookies();
        StringBuilder stringBuilder=new StringBuilder();
        if(cookies!=null){
            for(Cookie cookie:cookies){
                stringBuilder.append("名称"+cookie.getName()+"内容"+cookie.getValue());
            }
        }
        return "cookie信息"+stringBuilder.toString();
    }

    @RequestMapping("/getcookie")
    public String cookietest2(@CookieValue("name") String name){
        return "cooike获取成功"+name;
    }
}
